###################################################
# REDUCED FORM REGRESSIONS OF THE 25th PERCENTILE #
###################################################

# Author: Kasia Nalewajko
# First created:
# Replicated: 10 June 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("estimatr")) install.packages("estimatr")
if (!require("modelsummary")) install.packages("modelsummary")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/main.Rda")


# Logged
reducedmin_count <- lm_robust(formula = log(all_jewish_victims+1) ~ log(mpf1000+1) + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) + catholic_churches + log(ActionFrancaise_19_pct+1) 
                              + area_sqkm + longitude + longitudesq + latitude + latitudesq + zone5,
                              clusters = id_bureau,
                              fixed_effects = as.factor(ar_name),
                              data = subset(main, FFIFFCgentile < 25))

reducedfull_count <- lm_robust(formula = log(all_jewish_victims+1) ~ log(mpf1000+1) + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) + catholic_churches + log(ActionFrancaise_19_pct+1) 
                               + turnout_24_pct + log(nuance_droite_24_pct+1) + log(nuance_centredroit_24_pct+1) + log(nuance_centregauche_24_pct+1) + log(nuance_gauche_24_pct+1) + log(nuance_extremegauche_24_pct+1)
                               + area_sqkm + longitude + longitudesq + latitude + latitudesq + zone5,
                               clusters = id_bureau,
                               fixed_effects = as.factor(ar_name),
                               data = subset(main, FFIFFCgentile < 25))

# Proportion

reducedmin_prop <- lm_robust(formula = log(((all_jewish_victims+1)/(allocated_jpop+1)+1)) ~ log(mpf1000+1) + log(pop1936+1) + synagogues_dummy + log(allocated_jpop+1) + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) + catholic_churches + log(ActionFrancaise_19_pct+1) 
                             + area_sqkm + longitude + longitudesq + latitude + latitudesq + zone5,
                             clusters = id_bureau,
                             fixed_effects = as.factor(ar_name),
                             data = subset(main, FFIFFCgentile < 25))

reducedfull_prop <- lm_robust(formula = log(((all_jewish_victims+1)/(allocated_jpop+1)+1)) ~ log(mpf1000+1) + log(allocated_jpop+1) + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1) + log(DHI_milipol_sum1942+1) + catholic_churches + log(ActionFrancaise_19_pct+1) 
                              + turnout_24_pct + log(nuance_droite_24_pct+1) + log(nuance_centredroit_24_pct+1) + log(nuance_centregauche_24_pct+1) + log(nuance_gauche_24_pct+1) + log(nuance_extremegauche_24_pct+1)
                              + area_sqkm + longitude + longitudesq + latitude + latitudesq + zone5,
                              clusters = id_bureau,
                              fixed_effects = as.factor(ar_name),
                              data = subset(main, FFIFFCgentile < 25))

# Preview ----

modelsummary(list(reducedmin_count, reducedfull_count, reducedmin_prop, reducedfull_prop),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# EXPORT ----

modelsummary(list(reducedmin_count, reducedfull_count, reducedmin_prop, reducedfull_prop),
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_omit = "zone5",
             output = "latex",
             coef_rename = c("log(mpf1000 + 1)" = "WWI military death rates",
                             "log(pop1936 + 1)" = "1936 population",
                             "log(collabos_antijew1000 + 1)" = "Collaborators",
                             "log(DHI_milipol_sum1942 + 1)" = "1942 state presence",
                             "synagogues_dummy" = "Synagogues",
                             "area_sqkm" = "Area size (km2)",
                             "longitude" = "Longitude",
                             "latitude" = "Latitude",
                             "longitudesq" = "Longitude (sq)",
                             "latitudesq" = "Latitude (sq)",
                             "log(allocated_jpop + 1)" = "1941 Jewish population",
                             "catholic_churches" = "Catholic churches",
                             "log(ActionFrancaise_19_pct + 1)" = "Action Française vote 1919",
                             "turnout_24_pct" = "Turnout 1924",
                             "log(nuance_droite_24_pct + 1)" = "Right vote 1924",
                             "log(nuance_centredroit_24_pct + 1)" = "Centre-right vote 1924",
                             "log(nuance_centregauche_24_pct + 1)" = "Centre-left vote 1924",
                             "log(nuance_gauche_24_pct + 1)" = "Left vote 1924",
                             "log(nuance_extremegauche_24_pct + 1)" = "Extreme left vote 1924")
)

